package cdu.javaendwork.service.Impl.AdoptionMore;

import cdu.javaendwork.dao.Universal;
import cdu.javaendwork.dao.impl.UniversalImpl;
import cdu.javaendwork.model.sqlModel.Request;
import cdu.javaendwork.service.Interface.AdoptionMore.RequestService;

import java.util.Date;
import java.util.List;

public class RequestServiceImpl implements RequestService {

    Universal universal = new UniversalImpl();

    @Override
    public boolean insert(int host_user_id, int userid, int postid, int status, Date date) {
        return universal.insert("Request",host_user_id,userid,postid,status,date)==1;
    }

    @Override
    public boolean update(int id, int host_user_id, int userid, int postid, int status,Date date) {
        return universal.updateById("Request",id,host_user_id,userid,postid,status,date)==1;
    }

    @Override
    public boolean delete(int id) {
        return universal.deleteById("Request",id)==1;
    }



    @Override
    public List<Request> filterByUserIdLimit(int userid, int pageIndex, int pageSize) {
        return universal.filterLimit("Request","userid="+userid,pageIndex,pageSize);
    }

    @Override
    public boolean isAdopted(int postid) {
        List<Request> list = universal.filter("Request","status = 1 && postid = " + postid);
        return !list.isEmpty();
    }

    @Override
    public List<Request> filterByHostUserIdLimit(int host_user_id, int pageIndex, int pageSize) {

        return universal.filterLimit("Request","host_user_id="+host_user_id,pageIndex,pageSize);
    }

    @Override
    public List<Request> filterByPostIdLimit(int postid, int pageIndex, int pageSize) {
        return universal.filterLimit("Request","postid="+postid,pageIndex,pageSize);
    }
    @Override
    public List<Request> filterByPostidAndUserid(int postid, int userid) {
        return universal.filter("Request","postid=" +postid+" and userid!=" + userid);
    }

    @Override
    public Request findById(int id) {
        return universal.getById("Request" ,id);
    }

}
